package com.jingyanzi.privilege.service.impl;


import org.springframework.beans.factory.annotation.Autowired;

import com.jingyanzi.finance.service.impl.BaseServiceImpl;
import com.jingyanzi.privilege.dao.EmployeeSalesMapper;
import com.jingyanzi.privilege.domain.EmployeeDO;
import com.jingyanzi.privilege.domain.result.ResultDO;
import com.jingyanzi.privilege.domain.result.ResultSupport;
import com.jingyanzi.privilege.entity.EmployeeSales;
import com.jingyanzi.privilege.service.ISalesService;

public class SalesServiceImpl  extends BaseServiceImpl implements ISalesService {

	@Autowired
	private EmployeeSalesMapper employeeSalesMapper;

	@Override
	public ResultDO add(EmployeeDO domain) {
	
		ResultSupport result = new ResultSupport();
		
		EmployeeSales employeeSales = new EmployeeSales();
		
		int r = -1;
		employeeSales.setId(domain.getId());
		employeeSales.setGradeId(domain.getSalesGradeId());
		try {
			r = employeeSalesMapper.insertSelective(employeeSales);
		} catch (Exception e) {
			e.printStackTrace();
			//result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("添加销售失败");
			result.setSuccess(false);
			return result;
		}
		if (r < 0) {
			//result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("添加销售失败");
			result.setSuccess(false);
			return result;
		}

		result.setModel(ResultSupport.FIRST_MODEL_KEY, employeeSales.getId());

		return result;
	}

	@Override
	public ResultDO remove(int id) {
		
		ResultSupport result = new ResultSupport();
		
		int r = -1;
		
		try {
			r = employeeSalesMapper.deleteByPrimaryKey(id);
		} catch (Exception e) {
			e.printStackTrace();
			//result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("删除销售失败");
			result.setSuccess(false);
			return result;
		}
		if (r < 0) {
			//result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("删除销售失败");
			result.setSuccess(false);
			return result;
		}

		return result;
	}

	@Override
	public ResultDO modifi(EmployeeDO domain) {
	
		ResultSupport result = new ResultSupport();
		
		EmployeeSales employeeSales = new EmployeeSales();
		
		int r = -1;
		employeeSales.setId(domain.getId());
		employeeSales.setGradeId(domain.getSalesGradeId());
		try {
			r = employeeSalesMapper.updateByPrimaryKeySelective(employeeSales);
		} catch (Exception e) {
			e.printStackTrace();
			//result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("修改销售失败");
			result.setSuccess(false);
			return result;
		}
		if (r < 0) {
			//result.setErrorCode(ResultDO.SYSTEM_EXCEPTION_ERROR);
			result.setErrorMsg("修改销售失败");
			result.setSuccess(false);
			return result;
		}

		return result;
	}

}
